import {observable, action} from 'mobx'
import {ListViewPage} from 'weaver-mobile-page';
import * as API from '../../api/cptApi';

export default class ReportStore {
    @observable isLoading =true;
    @observable list1 = new ListViewPage.Store({route: '/report/1'});
    @observable list2 = new ListViewPage.Store({route: '/report/2'});
    @observable list3 = new ListViewPage.Store({route: '/report/3'});
    @observable list4 = new ListViewPage.Store({route: '/report/4'});
    @observable sum1 = 0;
    @observable sum2 = 0;
    @observable sum3 = 0;
    @observable sum4 = 0;
    @observable tabNum = '1';
    @observable nowPath = '';

    @action
    init = (path) => {
        this.nowPath = path;
        this.getCapitalReport(path);
    };
    @action
    setTabNum = (num) => {
        this.tabNum = num;
    };


    @action
    getCapitalReport = (type) => {        //待验收资
        this.isLoading =true;
        const params = {
            reporttype: type
        };
        API.getCapitalReport(params).then(res => {
            this.isLoading =false;
            const {datas, sum} = res;
            switch (type) {
                case 'group':
                    this.list1.getData({dataKey: datas});
                    this.sum1 = sum;
                    break;
                case 'resource':
                    this.list2.getData({dataKey: datas});
                    this.sum2 = sum;
                    break;
                case 'dept':
                    this.list3.getData({dataKey: datas});
                    this.sum3 = sum;
                    break;
                case 'state':
                    this.list4.getData({dataKey: datas});
                    this.sum4 = sum;
                    break;
                default:
                    break;
            }

        });
    }
}
